<?php
/**
 * Created by PhpStorm.
 * User: yangwang
 * Date: 2024-04-07
 * Time: 14:25
 */

namespace App\Http\Controllers\Cruise\Merchant;


use App\Http\Controllers\BaseController;
use App\Models\Cruise\ShopSelfCheckNotifyConfigModel;
use App\Remote\Rms\RmsUserRemote;
use App\Service\Cruise\Merchant\ShopSelfCheckNotifyConfigService;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class ShopCheckNotifyConfigController extends BaseController
{
    public function info(Request $request)
    {
        $shopId = (int)$request->header('shopId');
        $uid    = getRmsUserInfoByAuth()->id;

        return $this->success(ShopSelfCheckNotifyConfigService::info($shopId,$uid));
    }

    public function set(Request $request)
    {
        $shopId = (int)$request->header('shopId');
        $uid    = getRmsUserInfoByAuth()->id;

        $managerUids = array_column(
            RmsUserRemote::getShopManagerUserByShopId([$shopId])['lists'] ?? [], 'userId'
        );

        if (!in_array(getRmsUserId(), $managerUids)) {
            return $this->fail(400, '无店长权限');
        }

        $this->validate($request, [
            'id'                 => 'required|integer',
            'notifySwitch'       => 'integer|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::SWITCH_DESC_MAP)
                ),
            'notifyRoles'        => 'array|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::NOTIFY_ROLE_DESC_MAP)
                ),
            'notifyType'         => 'array|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::NOTIFY_TYPE_DESC_MAP)
                ),
            'kdNotifyTimeMap'    => 'integer|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::NOTIFY_TIME_KAIDANG_DESC_MAP)
                ),
            'sdNotifyTimeMap'    => 'integer|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::NOTIFY_TIME_SHOUDANG_DESC_MAP)
                ),
            'weekNotifyTimeMap'  => 'integer|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::NOTIFY_TIME_WEEKEND_DESC_MAP)
                ),
            'monthNotifyTimeMap' => 'integer|' . Rule::in(
                    array_keys(ShopSelfCheckNotifyConfigModel::NOTIFY_TIME_MONTH_DESC_MAP)
                ),
        ]);

        $input = $request->all();
        return $this->success(ShopSelfCheckNotifyConfigService::update($input, $shopId,$uid));
    }
}
